import 'package:shared_preferences/shared_preferences.dart';

class StartConfig {
  // 私有构造函数，防止外部创建实例
  StartConfig._privateConstructor();

  // 单例实例
  static final StartConfig _instance = StartConfig._privateConstructor();

  // 工厂构造函数，返回单例实例
  factory StartConfig() {
    return _instance;
  }

  // 检查是否是冷启动
  Future<bool> isColdStart() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    bool hasLaunchedBefore = prefs.getBool("hasLaunched") ?? true;
    print("hasLaunchedBefore ===== $hasLaunchedBefore");
    return hasLaunchedBefore;
  }

  // 设置冷启动标志为 false
  Future<void> setColdStartFlagFalse() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setBool("hasLaunched", false);
    print("Cold start flag has been set to false.");
  }
}
